
"""

#1、 alert弹框： 本质上是js的弹框 ，需要切换后将它关掉。 ==最常见 优先掌握
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Chrome()
driver.maximize_window()
# driver.get('file:///D:/Pycharm_Project/alert_demo.html')
driver.get('file:///E:/3.Package/10.Pycharm/python/alert_demo.html.html')
sleep(2)  # 强制等待

# 点击触发弹框
driver.find_element(By.ID,'alert').click()

# 切换到弹框 并进行操作
# print(driver.switch_to.alert.text) # 获取弹框文本 并打印
driver.switch_to.alert.accept() # 进行确认操作 关闭弹框
# driver.switch_to.alert.dismiss() # 进行确认操作 关闭弹框
sleep(2)
# driver.close()
"""

# 练习
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Chrome()
driver.maximize_window()
driver.get(f"file:///E:/3.Package/10.Pycharm/python/alert_demo.html.html")

driver.find_element(By.XPATH,"//button[text()='点击弹出确认框']").click()
sleep(2)
# driver.switch_to.alert.accept() #确定
driver.switch_to.alert.dismiss()
sleep(2)

# 总结
# 需要找到下拉框地址，然后元素定位，点击确定  注意以下写法
# driver.switch_to.alert.accept() #确定
# driver.switch_to.alert.dismiss() #取消